package com.hod.client.client;

import java.util.Date;

import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.ListBox;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.data.Record;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
import com.gwtext.client.widgets.form.DateField;
import com.gwtext.client.widgets.form.FieldSet;
import com.gwtext.client.widgets.form.Label;
import com.gwtext.client.widgets.form.NumberField;
import com.gwtext.client.widgets.form.TextField;
import com.gwtext.client.widgets.form.VType;
import com.hod.client.HOD;
import com.hod.client.backend.orm.client.GearsDataObject;
import com.hod.client.backend.orm.client.GearsDataStore;
import com.hod.client.bed.Bed;
import com.hod.client.bed.BedRecordset;
import com.hod.client.frontend.HODForm;
import com.hod.client.room.Room;
import com.hod.client.room.RoomRecordset;

public class ClientFormPanel extends HODForm {
	
	protected final TextField txtIdClient  = new TextField ("idClient","idClient",150); 					 
	protected final TextField txtname  = new TextField ("name","name",150); 																		 
	protected final TextField txtsurname  = new TextField ("surname","surname",150); 																		 
	protected final TextField txtaddress  = new TextField ("address","address",150); 																		 
	protected final TextField txtcity  = new TextField ("city","city",150); 																		 
	protected final ListBox txtcountry  = new ListBox(); 																		 
	protected final TextField txtgender  = new TextField ("gender","gender",150); 																		 
	protected final TextField txtccNumber  = new TextField ("ccNumber","ccNumber",150); 																		 
	protected final TextField txtccCode  = new TextField ("ccCode","ccCode",150); 																		 
	protected final TextField txthowKnowsUs  = new TextField ("howKnowsUs","howKnowsUs",150); 																		 
	protected final DateField txtbornDate  = new DateField ("bornDate","bornDate",150); 																		 
	protected final TextField txtidNumber  = new TextField ("idNumber","idNumber",150); 																		 
	protected final TextField txtkindOfId  = new TextField ("kindOfId","kindOfId",150); 																		 
	protected final TextField txtnationality  = new TextField ("nationality","nationality",150); 																											 
	//protected final CheckBox txtactive = new CheckBox ("active"); 									 
	protected final TextField txtemail  = new TextField ("email","email",150);
	
	protected final DateField txtcheckIn  = new DateField ("checkIn","checkIn",150);
	protected final DateField txtcheckOut  = new DateField ("checkOut","checkOut",150);
	protected final CheckBox txtToalla = new CheckBox ("toalla"); 
	protected final NumberField txtTotal  = new NumberField ("total","total",150);
	protected final CheckBox txtPago = new CheckBox ("pago");
	protected final NumberField txtVoucher  = new NumberField ("voucher","voucher",150);
	protected final CheckBox txtDebe = new CheckBox ("Debe");
	protected final DateField txtReservationDate  = new DateField ("reservationDate","reservationDate",150);
	protected final NumberField txtNumberOfNights  = new NumberField ("numberOfNights","numberOfNights",150);
    protected final ListBox txtIdRoom = new ListBox();
    protected final ListBox txtIdBed = new ListBox();
	
	public final boolean ResumeMode = false;

	public ClientFormPanel(GearsDataStore ds){
		super(ds);
		// TODO Auto-generated constructor stub
		if (!ResumeMode)
		   add(createFieldSet());
		else
		   add(createResumeFieldSet());	
        createButtons();
	}

	@Override
	protected void createButtons() {
		// TODO Auto-generated method stub
		 ButtonListenerAdapter savelistener = new ButtonListenerAdapter() {
            public void onClick(Button button, EventObject e) {
            	try {
            		Client o = null;
            		if (txtIdClient.getText()==""){
            			o = new Client();
            		}else{
            			o = (Client) ds.findById(new Integer(txtIdClient.getText()));
            		}
            		try {
						o.setName(txtname.getText());
					} catch (Exception e1) {
						// TODO Auto-generated catch block
					}
            	    try {
						o.setSurname(txtsurname.getText());
					} catch (Exception e1) {
						// TODO Auto-generated catch block
					}
            	    try {
						o.setAddress(txtaddress.getText());
					} catch (Exception e1) {
						// TODO Auto-generated catch block
					}
            	    try {
						o.setCity(txtcity.getText());
					} catch (Exception e1) {
						// TODO Auto-generated catch block
					}
            	    try {
						o.setCountry(txtcountry.getValue(txtcountry.getSelectedIndex()));
					} catch (Exception e1) {
						// TODO Auto-generated catch block
					}
            	    try {
						o.setGender(txtgender.getText());
					} catch (Exception e1) {
						// TODO Auto-generated catch block
					}
            	    try {
						o.setCcNumber(txtccNumber.getText());
					} catch (Exception e1) {
						// TODO Auto-generated catch block
					}
            	    try {
						o.setCcCode(txtccCode.getText());
					} catch (Exception e1) {
						// TODO Auto-generated catch block
					}
            	    try {
						o.setHowKnowsUs(txthowKnowsUs.getText());
					} catch (Exception e1) {
						// TODO Auto-generated catch block
					}
            	    try {
						o.setBornDate(txtbornDate.getValue());
					} catch (Exception e1) {
						// TODO Auto-generated catch block
					}
            	    try {
						o.setIdNumber(txtidNumber.getText());
					} catch (Exception e1) {
						// TODO Auto-generated catch block
					}
            	    try {
						o.setKindOfId(txtkindOfId.getText());
					} catch (Exception e1) {
						// TODO Auto-generated catch block
					}
            	    try {
						o.setNationality(txtnationality.getText());
					} catch (Exception e1) {
						// TODO Auto-generated catch block
					}
            	    try {
						//o.setActive(txtactive.getValue());
					} catch (Exception e1) {
						// TODO Auto-generated catch block
					}
            	    try {
						o.setEmail(txtemail.getText());
					} catch (Exception e1) {
						// TODO Auto-generated catch block
					}            	    
            	    try {
						o.setCheckIn(txtcheckIn.getValue());
					} catch (Exception e1) {
						// TODO Auto-generated catch block
					}
            	    try {
						o.setCheckOut(txtcheckOut.getValue());
					} catch (Exception e1) {
					}
            	    try {
						o.setToalla(txtToalla.getValue());
					} catch (Exception e1) {
						// TODO Auto-generated catch block
					}
            	    try {
						o.setTotal((Float)txtTotal.getValue());
					} catch (Exception e1) {
						
					}
            	    try {
						o.setPago(txtPago.getValue());
					} catch (Exception e1) {
						// TODO Auto-generated catch block
					}
            	    try {
						o.setVoucher((Float)txtVoucher.getValue());
					} catch (Exception e1) {

					}
            	    try {
						o.setDebe(txtDebe.getValue());
					} catch (Exception e1) {
					}
            	    try {
						o.setReservationDate(txtReservationDate.getValue());
					} catch (Exception e1) {
					}
            	    try {
						o.setNumberOfNights((Integer)txtNumberOfNights.getValue());
					} catch (Exception e1) {
					} 
            	    try {
						o.setIdRoom(Integer.valueOf(txtIdRoom.getValue(txtIdRoom.getSelectedIndex())));
					} catch (Exception e1) {
					}
                    try {
						o.setIdBed(Integer.valueOf(txtIdBed.getValue(txtIdBed.getSelectedIndex())));
					} catch (Exception e1) {
						// TODO Auto-generated catch block
						o.setIdBed(0);
					}
                    ds.save(o);                        
                    HOD.reload();
					} catch (Exception e1) {
						// TODO Auto-generated catch block
						Window.alert(e1.getMessage());
					}
            }
        };
        ButtonListenerAdapter deletelistener = new ButtonListenerAdapter() {
            public void onClick(Button button, EventObject e) {
            	try {
            		ds.delete((Client) ds.findById(new Integer(txtIdClient.getText())));
            		HOD.reload();
					} catch (Exception e1) {
						// TODO Auto-generated catch block
						Window.alert(e1.getMessage());
					}
            }
        };
        ButtonListenerAdapter createlistener = new ButtonListenerAdapter() {
            public void onClick(Button button, EventObject e) {
            	try {
            		getForm().reset();
					} catch (Exception e1) {
						// TODO Auto-generated catch block
						Window.alert(e1.getMessage());
					}
            }
        };
        
        ButtonListenerAdapter cancellistener = new ButtonListenerAdapter() {
            public void onClick(Button button, EventObject e) {
            	try {
            		
					} catch (Exception e1) {
						// TODO Auto-generated catch block
						Window.alert(e1.getMessage());
					}
            }
        };
        	           
        
        Button save = new Button("Save", savelistener);
        Button delete = new Button("Delete", deletelistener);
		 Button newRecord = new Button("New", createlistener);
        Button cancel = new Button("Cancel");

        addButton(save);
        addButton(delete);
        addButton(cancel);
        addButton(newRecord);

	}
	
	void initCountryList(){
		txtcountry.addItem("OTHER"); 
        txtcountry.addItem("Afghanistan"); 
        txtcountry.addItem("Albania"); 
        txtcountry.addItem("Algeria"); 
        txtcountry.addItem("American Samoa" );
        txtcountry.addItem("Andorra" );
        txtcountry.addItem("Angola"); 
        txtcountry.addItem("Anguilla" );
        txtcountry.addItem("Antarctica"); 
        txtcountry.addItem("Antigua and Barbuda" );
        txtcountry.addItem("Argentina" );
        txtcountry.addItem("Armenia" );
        txtcountry.addItem("Aruba" );
        txtcountry.addItem("Australia" );
        txtcountry.addItem("Austria" );
        txtcountry.addItem("Azerbaijan" );
        txtcountry.addItem("Bahamas" );
        txtcountry.addItem("Bahrain" );
        txtcountry.addItem("Bangladesh" );
        txtcountry.addItem("Barbados" );
        txtcountry.addItem("Belarus" );
        txtcountry.addItem("Belgium" );
        txtcountry.addItem("Belize" );
        txtcountry.addItem("Benin" );
        txtcountry.addItem("Bermuda" );
        txtcountry.addItem("Bhutan" );
        txtcountry.addItem("Bolivia" );
        txtcountry.addItem("Bosnia and Herzeg..." );
        txtcountry.addItem("Botswana" );
        txtcountry.addItem("Bouvet Island" );
        txtcountry.addItem("Brazil" );
        txtcountry.addItem("British Indian Ocean" );
        txtcountry.addItem("Brunei Darussalam" );
        txtcountry.addItem("Bulgaria" );
        txtcountry.addItem("Burkina Faso" );
        txtcountry.addItem("Burundi" );
        txtcountry.addItem("Cambodia" );
        txtcountry.addItem("Cameroon" );
        txtcountry.addItem("Canada" );
        txtcountry.addItem("Cape Verde" );
        txtcountry.addItem("Cayman Islands" );
        txtcountry.addItem("Central African Rep." );
        txtcountry.addItem("Chad" );
        txtcountry.addItem("Chile" );
        txtcountry.addItem("China" );
        txtcountry.addItem("Christmas Island" );
        txtcountry.addItem("Cocos (Keeling) Isl." );
        txtcountry.addItem("Colombia" );
        txtcountry.addItem("Comoros" );
        txtcountry.addItem("Congo" );
        txtcountry.addItem("Cook Islands" );
        txtcountry.addItem("Costa Rica" );
        txtcountry.addItem("Cote D'Ivoire" );
        txtcountry.addItem("Croatia (Hrvatska)" );
        txtcountry.addItem("Cuba" );
        txtcountry.addItem("Cyprus" );
        txtcountry.addItem("Czech Republic" );
        txtcountry.addItem("Denmark" );
        txtcountry.addItem("Djibouti" );
        txtcountry.addItem("Dominica" );
        txtcountry.addItem("Dominican Rep." );
        txtcountry.addItem("East Timor" );
        txtcountry.addItem("Ecuador" );
        txtcountry.addItem("Egypt" );
        txtcountry.addItem("El Salvador" );
        txtcountry.addItem("Equatorial Guinea" );
        txtcountry.addItem("Eritrea" );
        txtcountry.addItem("Estonia" );
        txtcountry.addItem("Ethiopia" );
        txtcountry.addItem("Falkland Islands" );
        txtcountry.addItem("Faroe Islands" );
        txtcountry.addItem("Fiji" );
        txtcountry.addItem("Finland" );
        txtcountry.addItem("France" );
        txtcountry.addItem("France, Metropolitan" );
        txtcountry.addItem("French Guiana" );
        txtcountry.addItem("French Polynesia" );
        txtcountry.addItem("French Southern terr." );
        txtcountry.addItem("Gabon" );
        txtcountry.addItem("Gambia" );
        txtcountry.addItem("Georgia" );
        txtcountry.addItem("Germany" );
        txtcountry.addItem("Ghana" );
        txtcountry.addItem("Gibraltar" );
        txtcountry.addItem("Greece" );
        txtcountry.addItem("Greenland" );
        txtcountry.addItem("Grenada" );
        txtcountry.addItem("Guadeloupe" );
        txtcountry.addItem("Guam" );
        txtcountry.addItem("Guatemala" );
        txtcountry.addItem("Guinea" );
        txtcountry.addItem("Guinea-Bissau" );
        txtcountry.addItem("Guyana" );
        txtcountry.addItem("Haiti" );
        txtcountry.addItem("Heard and Mc Donalds" );
        txtcountry.addItem("Honduras" );
        txtcountry.addItem("Hong Kong" );
        txtcountry.addItem("Hungary" );
        txtcountry.addItem("Iceland" );
        txtcountry.addItem("India" );
        txtcountry.addItem("Indonesia" );
        txtcountry.addItem("Iran" );
        txtcountry.addItem("Iraq" );
        txtcountry.addItem("Ireland" );
        txtcountry.addItem("Israel" );
        txtcountry.addItem("Italy" );
        txtcountry.addItem("Jamaica" );
        txtcountry.addItem("Japan" );
        txtcountry.addItem("Jordan" );
        txtcountry.addItem("Kazakhstan" );
        txtcountry.addItem("Kenya" );
        txtcountry.addItem("Kiribati" );
        txtcountry.addItem("Korea" );
        txtcountry.addItem("Korea, Republic of" );
        txtcountry.addItem("Kuwait" );
        txtcountry.addItem("Kyrgyzstan" );
        txtcountry.addItem("Lao" );
        txtcountry.addItem("Latvia" );
        txtcountry.addItem("Lebanon" );
        txtcountry.addItem("Lesotho" );
        txtcountry.addItem("Liberia" );
        txtcountry.addItem("Libyan Arab Jamahiriya" );
        txtcountry.addItem("Liechtenstein" );
        txtcountry.addItem("Lithuania" );
        txtcountry.addItem("Luxembourg" );
        txtcountry.addItem("Macau" );
        txtcountry.addItem("Macedonia" );
        txtcountry.addItem("Madagascar" );
        txtcountry.addItem("Malawi" );
        txtcountry.addItem("Malaysia" );
        txtcountry.addItem("Maldives" );
        txtcountry.addItem("Mali" );
        txtcountry.addItem("Malta" );
        txtcountry.addItem("Marshall Islands" );
        txtcountry.addItem("Martinique" );
        txtcountry.addItem("Mauritania" );
        txtcountry.addItem("Mauritius" );
        txtcountry.addItem("Mayotte" );
        txtcountry.addItem("Mexico" );
        txtcountry.addItem("Micronesia" );
        txtcountry.addItem("Moldova" );
        txtcountry.addItem("Monaco" );
        txtcountry.addItem("Mongolia" );
        txtcountry.addItem("Montserrat" );
        txtcountry.addItem("Morocco" );
        txtcountry.addItem("Mozambique" );
        txtcountry.addItem("Myanmar" );
        txtcountry.addItem("Namibia" );
        txtcountry.addItem("Nauru" );
        txtcountry.addItem("Nepal" );
        txtcountry.addItem("Netherlands" );
        txtcountry.addItem("Netherlands Antilles" );
        txtcountry.addItem("New Caledonia" );
        txtcountry.addItem("New Zealand" );
        txtcountry.addItem("Nicaragua" );
        txtcountry.addItem("Niger" );
        txtcountry.addItem("Nigeria" );
        txtcountry.addItem("Niue" );
        txtcountry.addItem("Norfolk Island" );
        txtcountry.addItem("Northern Mariana Islands" );
        txtcountry.addItem("Norway" );
        txtcountry.addItem("Oman" );
        txtcountry.addItem("Pakistan" );
        txtcountry.addItem("Palau" );
        txtcountry.addItem("Panama" );
        txtcountry.addItem("Papua New Guinea" );
        txtcountry.addItem("Paraguay" );
        txtcountry.addItem("Peru" );
        txtcountry.addItem("Philippines" );
        txtcountry.addItem("Pitcairn" );
        txtcountry.addItem("Poland" );
        txtcountry.addItem("Portugal" );
        txtcountry.addItem("Puerto Rico" );
        txtcountry.addItem("Qatar" );
        txtcountry.addItem("Reunion" );
        txtcountry.addItem("Romania" );
        txtcountry.addItem("Russian Federation" );
        txtcountry.addItem("Rwanda" );
        txtcountry.addItem("Saint Kitts and Nevis" );
        txtcountry.addItem("Saint Lucia" );
        txtcountry.addItem("Saint Vincent and Grenadines" );
        txtcountry.addItem("Samoa" );
        txtcountry.addItem("San Marino" );
        txtcountry.addItem("Sao Tome and Principe" );
        txtcountry.addItem("Saudi Arabia" );
        txtcountry.addItem("Senegal" );
        txtcountry.addItem("Seychelles" );
        txtcountry.addItem("Sierra Leone" );
        txtcountry.addItem("Singapore" );
        txtcountry.addItem("Slovakia (Slovak Rep)" );
        txtcountry.addItem("Slovenia" );
        txtcountry.addItem("Solomon Islands" );
        txtcountry.addItem("Somalia" );
        txtcountry.addItem("South Africa" );
        txtcountry.addItem("Spain" );
        txtcountry.addItem("Sri Lanka" );
        txtcountry.addItem("St. Helena" );
        txtcountry.addItem("St. Pierre and Miquelon" );
        txtcountry.addItem("Sudan" );
        txtcountry.addItem("Suriname" );
        txtcountry.addItem("Svalbard Jan Mayen" );
        txtcountry.addItem("Swaziland" );
        txtcountry.addItem("Sweden" );
        txtcountry.addItem("Switzerland" );
        txtcountry.addItem("Syrian Arab Republic" );
        txtcountry.addItem("Taiwan" );
        txtcountry.addItem("Tajikistan" );
        txtcountry.addItem("Tanzania" );
        txtcountry.addItem("Thailand" );
        txtcountry.addItem("Togo" );
        txtcountry.addItem("Tokelau" );
        txtcountry.addItem("Tonga" );
        txtcountry.addItem("Trinidad and Tobago" );
        txtcountry.addItem("Tunisia" );
        txtcountry.addItem("Turkey" );
        txtcountry.addItem("Turkmenistan" );
        txtcountry.addItem("Turks and Caicos Islands" );
        txtcountry.addItem("Tuvalu" );
        txtcountry.addItem("Uganda" );
        txtcountry.addItem("Ukraine" );
        txtcountry.addItem("United Arab Emirates" );
        txtcountry.addItem("United Kingdom" );
        txtcountry.addItem("United States" );
        txtcountry.addItem("United States Minor Islands" );
        txtcountry.addItem("Uruguay" );
        txtcountry.addItem("Uzbekistan" );
        txtcountry.addItem("Vanuatu" );
        txtcountry.addItem("Vatican City State" );
        txtcountry.addItem("Venezuela" );
        txtcountry.addItem("Viet NAM" );
        txtcountry.addItem("Virgin Islands (British)" );
        txtcountry.addItem("Virgin Islands (U.S.)" );
        txtcountry.addItem("Wallis and Futuna Islands" );
        txtcountry.addItem("Western Sahara" );
        txtcountry.addItem("Yemen" );
        txtcountry.addItem("Yugoslavia" );
        txtcountry.addItem("Zaire" );
        txtcountry.addItem("Zambia" );
        txtcountry.addItem("Zimbabwe" );
	}
	
	@Override
	protected FieldSet createFieldSet() {
		//Listado de paises
		initCountryList();
				
		for(Room r: RoomRecordset.getRooms()){            	
        	txtIdRoom.addItem(r.getNumber(),String.valueOf(r.getIdRoom()));
        }
		
		for(Bed r: BedRecordset.getBed())            	
        	txtIdBed.addItem(r.getNumber()+"",String.valueOf(r.getIdBed()));
		
		txtIdRoom.addChangeHandler(new ChangeHandler(){

			@Override
			public void onChange(ChangeEvent event) {
				txtIdBed.clear(); 
				for(Bed r: BedRecordset.getBed(Integer.valueOf(txtIdRoom.getValue(txtIdRoom.getSelectedIndex())))){            	
		        	txtIdBed.addItem(r.getNumber()+"",String.valueOf(r.getIdBed()));
		        }
				
			}
			
		});
		
		// TODO Auto-generated method stub
		    FieldSet fieldSet = new FieldSet();
		    
		    
	        fieldSet.setLabelWidth(80);
	        fieldSet.setTitle("Details");
	        //fieldSet.setCollapsible(true);
	        //fieldSet.setAutoHeight(true);
	        fieldSet.setBorder(false);

	        //the field names msut match the data field values from the Store
	        FieldSet fieldSet1 = new FieldSet();
	        fieldSet1.setTitle("Datos basicos");
	        fieldSet1.setCollapsible(true);
	        fieldSet1.add(txtIdClient);
	        fieldSet1.add(txtname);
	        fieldSet1.add(txtsurname);
	        fieldSet1.add(txtaddress);
	        fieldSet1.add(txtcity);
	        fieldSet1.add(new Label("Pais"));
	        fieldSet1.add(txtcountry);
	        fieldSet1.add(new HTML("<BR/>"));
	        fieldSet1.add(txtgender);
	        fieldSet1.add(txtemail);
	        
	        txtIdClient.setVisible(false);
	        txtIdClient.setHideLabel(true);
	        txtname.setAllowBlank(false);
	        txtsurname.setAllowBlank(false);
	        txtaddress.setAllowBlank(false);
	        txtcity.setAllowBlank(false);
	        txtgender.setAllowBlank(false);
	        txtemail.setAllowBlank(false);
	        txtccNumber.setAllowBlank(false);
	        txtccCode.setAllowBlank(false);
	        txthowKnowsUs.setAllowBlank(false);
	        txtbornDate.setAllowBlank(false);
	        txtidNumber.setAllowBlank(false);
	        txtkindOfId.setAllowBlank(false);
	        txtnationality.setAllowBlank(false);	
	        txtcheckIn.setAllowBlank(false);
	        txtcheckOut.setAllowBlank(false);
	        txtTotal.setAllowBlank(false);
	        txtTotal.setAllowDecimals(true);
	        txtTotal.setAllowNegative(false);
	        txtVoucher.setAllowBlank(false);
	        txtVoucher.setAllowDecimals(true);
	        txtVoucher.setAllowNegative(false);
	        txtReservationDate.setAllowBlank(true);
	        txtNumberOfNights.setAllowBlank(false);
	        txtNumberOfNights.setAllowDecimals(false);
	        txtNumberOfNights.setAllowNegative(false);
	        
	        
	        txtemail.setVtype(VType.EMAIL);	       
	        txtgender.setVtype(VType.ALPHA);
	        txtemail.setVtype(VType.EMAIL);
	        	        
	        
	        FieldSet fieldSet2 = new FieldSet();
	        fieldSet2.setCollapsible(true);
	        fieldSet2.setTitle("Datos adicionales");
	        fieldSet2.add(txtccNumber);
	        fieldSet2.add(txtccCode);
	        fieldSet2.add(txthowKnowsUs);
	        fieldSet2.add(txtbornDate);
	        fieldSet2.add(txtidNumber);
	        fieldSet2.add(txtkindOfId);
	        fieldSet2.add(txtnationality);
	        	        
	        FieldSet fieldSet3 = new FieldSet();
	        fieldSet3.setTitle("Hospedaje");
	        fieldSet3.setCollapsible(true);
	        fieldSet3.add(new Label("Habitacion"));
	        fieldSet3.add(txtIdRoom);
	        fieldSet3.add(new HTML("<BR/>"));
	        fieldSet3.add(new Label("Cama"));
	        fieldSet3.add(txtIdBed);
	        fieldSet3.add(new HTML("<BR/>"));


	        txtIdClient.setReadOnly(true);

	        fieldSet3.add(txtcheckIn);
	        fieldSet3.add(txtcheckOut);
	        
	        FieldSet fieldSet4 = new FieldSet();
	        fieldSet4.setTitle("Detalles adicionales de hospedaje");
	        fieldSet4.setCollapsible(true);
	        fieldSet4.add(txtToalla);
	        fieldSet4.add(txtTotal);
	        fieldSet4.add(txtPago);
	        fieldSet4.add(txtVoucher);
	        fieldSet4.add(txtDebe);
	        fieldSet4.add(txtReservationDate);
	        fieldSet4.add(txtNumberOfNights);
	        

	        fieldSet.add(fieldSet1);
	        fieldSet.add(fieldSet2);
	        fieldSet.add(fieldSet3);
	        fieldSet.add(fieldSet4);
	        
	        	        

	        return fieldSet;
	}

	@Override
	public void updateDataControls(Record record) {
		// TODO Auto-generated method stub
		getForm().loadRecord(record);
		txtToalla.setValue(record.getAsBoolean("toalla")); 
		txtPago.setValue(record.getAsBoolean("pago"));
		txtDebe.setValue(record.getAsBoolean("debe"));
		if (record.getAsString("country").isEmpty()) record.set("country", "OTHER");
		for(int i=0;i<txtcountry.getItemCount();i++){
			if (txtcountry.getItemText(i).equals(record.getAsString("country"))){
				txtcountry.setSelectedIndex(i);
				break;
			}	        	    
        }
        for (int i=0;i<txtIdRoom.getItemCount();i++)
            if (Integer.valueOf(txtIdRoom.getValue(i)).equals(record.getAsInteger("idRoom")))
            	txtIdRoom.setItemSelected(i, true);
        for (int i=0;i<txtIdBed.getItemCount();i++)
            if (Integer.valueOf(txtIdBed.getValue(i)).equals(record.getAsInteger("idBed")))
            	txtIdBed.setItemSelected(i, true);
	}

	@Override
	public void setObject(GearsDataObject object) {
		// TODO Auto-generated method stub
		Client o = (Client)object;
		try {
			txtIdClient.setValue(o.getIdClient().toString());
		} catch (Exception e2) {
			// TODO Auto-generated catch block
			txtIdClient.setValue("");
		}
		try {
			txtname.setValue(o.getName());
		} catch (Exception e2) {
			// TODO Auto-generated catch block
			txtname.setValue("");
		}
		try {
			txtsurname.setValue(o.getSurname());
		} catch (Exception e2) {
			// TODO Auto-generated catch block
			txtsurname.setValue("");
		}
		try {
			txtaddress.setValue(o.getAddress());
		} catch (Exception e2) {
			// TODO Auto-generated catch block
			txtaddress.setValue("");
		}
		try {
			txtcity.setValue(o.getCity());
		} catch (Exception e2) {
			// TODO Auto-generated catch block
			txtcity.setValue("");
		}
		try {
			if (o.getCountry().isEmpty())
				o.setCountry("OTHER");
			for(int i=0;i<txtcountry.getItemCount();i++){
				if (txtcountry.getItemText(i).equals(o.getCountry())){
					txtcountry.setSelectedIndex(i);
					break;
				}	        	    
	        }
		} catch (Exception e2) {
			// TODO Auto-generated catch block
		}
		try {
			txtgender.setValue(o.getGender());
		} catch (Exception e2) {
			// TODO Auto-generated catch block
			txtgender.setValue("");
		}
		try {
			txtccNumber.setValue(o.getCcNumber());
		} catch (Exception e2) {
			// TODO Auto-generated catch block
			txtccNumber.setValue("");
		}
		try {
			txtccCode.setValue(o.getCcCode());
		} catch (Exception e2) {
			// TODO Auto-generated catch block
			txtccCode.setValue("");
		}
		try {
			txthowKnowsUs.setValue(o.getHowKnowsUs());
		} catch (Exception e2) {
			// TODO Auto-generated catch block
			txthowKnowsUs.setValue("");
		}
		try {
			txtbornDate.setValue(o.getBornDate());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			txtbornDate.setValue(new Date());
		}
		try {
			txtidNumber.setValue(o.getIdNumber());
		} catch (Exception e4) {
			// TODO Auto-generated catch block
			txtidNumber.setValue("");
		}
		try {
			txtkindOfId.setValue(o.getKindOfId());
		} catch (Exception e3) {
			// TODO Auto-generated catch block
			txtkindOfId.setValue("");
		}
		try {
			txtnationality.setValue(o.getNationality());
		} catch (Exception e2) {
			// TODO Auto-generated catch block
			txtnationality.setValue("");
		}
		try {
			//txtactive.setValue(o.getActive());
		} catch (Exception e1) {
			// TODO Auto-generated catch block
		}
		txtemail.setValue(o.getEmail());	
		try {
			txtcheckIn.setValue(o.getCheckIn());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			txtcheckIn.setValue(new Date());
		}
        try {
			txtcheckOut.setValue(o.getCheckOut());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			txtcheckOut.setValue(new Date());
		}
        try {
			txtToalla.setValue(o.getToalla());
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			txtToalla.setValue(false);
		}
        try {
			txtTotal.setValue(o.getTotal());
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			txtTotal.setValue(0);
		}
        try {
			txtPago.setValue(o.getPago());
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			txtPago.setValue(false);
		}
        try {
			txtVoucher.setValue(o.getVoucher());
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			txtVoucher.setValue("");
		}
        try {
			txtDebe.setValue(o.getDebe());
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			txtDebe.setValue(false);
		}
        try {
			txtReservationDate.setValue(o.getReservationDate());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			txtReservationDate.setValue(new Date());
		}
        try {
			txtNumberOfNights.setValue(o.getNumberOfNights());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			txtNumberOfNights.setValue(1);
		}
	
        for (int i=0;i<txtIdRoom.getItemCount();i++){
            if (Integer.valueOf(txtIdRoom.getValue(i)).equals(o.getIdRoom()))
            	txtIdRoom.setItemSelected(i, true);
        }
        if (!o.getIdBed().equals(0)){
        	txtIdBed.setEnabled(true);
	        for (int i=0;i<txtIdBed.getItemCount();i++)
	            if (Integer.valueOf(txtIdBed.getValue(i)).equals(o.getIdBed()))
	            	txtIdBed.setItemSelected(i, true);
        }else{
        	txtIdBed.setEnabled(false);
        }
	}
	
	private FieldSet createResumeFieldSet() {
		// TODO Auto-generated method stub
		
		initCountryList();
		
		for(Room r: RoomRecordset.getRooms()){            	
        	txtIdRoom.addItem(r.getNumber(),String.valueOf(r.getIdRoom()));
        }
		for(Bed r: BedRecordset.getBed())            	
        	txtIdBed.addItem(r.getNumber()+"",String.valueOf(r.getIdBed()));
		txtIdRoom.addChangeHandler(new ChangeHandler(){

			@Override
			public void onChange(ChangeEvent event) {
				txtIdBed.clear(); 
				for(Bed r: BedRecordset.getBed(Integer.valueOf(txtIdRoom.getValue(txtIdRoom.getSelectedIndex())))){            	
		        	txtIdBed.addItem(r.getNumber()+"",String.valueOf(r.getIdBed()));
		        }
				
			}
			
		});
		
		// TODO Auto-generated method stub
		    FieldSet fieldSet = new FieldSet();
		    
		    
	        fieldSet.setLabelWidth(80);
	        fieldSet.setTitle("Details");
	        //fieldSet.setCollapsible(true);
	        //fieldSet.setAutoHeight(true);
	        fieldSet.setBorder(false);

	        //the field names msut match the data field values from the Store
	        FieldSet fieldSet1 = new FieldSet();
	        fieldSet1.setTitle("Datos basicos");
	        fieldSet1.setCollapsible(true);
	        fieldSet1.add(txtIdClient);
	        fieldSet1.add(txtname);
	        fieldSet1.add(txtsurname);
	        fieldSet1.add(txtaddress);
	        fieldSet1.add(txtcity);
	        fieldSet1.add(new Label("Pais"));
	        fieldSet1.add(txtcountry);
	        fieldSet1.add(new HTML("<BR/>"));
	        fieldSet1.add(txtgender);
	        fieldSet1.add(txtemail);
	        
	        txtIdClient.setVisible(false);
	        txtIdClient.setHideLabel(true);
	        txtname.setAllowBlank(false);
	        txtsurname.setAllowBlank(false);
	        txtaddress.setAllowBlank(false);
	        txtcity.setAllowBlank(false);
	        txtgender.setAllowBlank(false);
	        txtemail.setAllowBlank(false);
	        txtccNumber.setAllowBlank(false);
	        txtccCode.setAllowBlank(false);
	        txthowKnowsUs.setAllowBlank(false);
	        txtbornDate.setAllowBlank(false);
	        txtidNumber.setAllowBlank(false);
	        txtkindOfId.setAllowBlank(false);
	        txtnationality.setAllowBlank(false);	
	        txtcheckIn.setAllowBlank(false);
	        txtcheckOut.setAllowBlank(false);
	        txtTotal.setAllowBlank(false);
	        txtTotal.setAllowDecimals(true);
	        txtTotal.setAllowNegative(false);
	        txtVoucher.setAllowBlank(false);
	        txtVoucher.setAllowDecimals(true);
	        txtVoucher.setAllowNegative(false);
	        txtReservationDate.setAllowBlank(true);
	        txtNumberOfNights.setAllowBlank(false);
	        txtNumberOfNights.setAllowDecimals(false);
	        txtNumberOfNights.setAllowNegative(false);
	        
	        
	        txtemail.setVtype(VType.EMAIL);
	        txtgender.setVtype(VType.ALPHA);
	        txtemail.setVtype(VType.EMAIL);
	        	        
	        
	        FieldSet fieldSet2 = new FieldSet();
	        fieldSet2.setCollapsible(true);
	        fieldSet2.setTitle("Datos adicionales");
	        fieldSet2.add(txtccNumber);
	        fieldSet2.add(txtccCode);
	        fieldSet2.add(txthowKnowsUs);
	        fieldSet2.add(txtbornDate);
	        fieldSet2.add(txtidNumber);
	        fieldSet2.add(txtkindOfId);
	        fieldSet2.add(txtnationality);
	        	        
	        FieldSet fieldSet3 = new FieldSet();
	        fieldSet3.setTitle("Hospedaje");
	        fieldSet3.setCollapsible(true);
	        fieldSet3.add(new Label("Habitacion"));
	        fieldSet3.add(txtIdRoom);
	        fieldSet3.add(new HTML("<BR/>"));
	        fieldSet3.add(new Label("Cama"));
	        fieldSet3.add(txtIdBed);
	        fieldSet3.add(new HTML("<BR/>"));


	        txtIdClient.setReadOnly(true);

	        
	        
	        FieldSet fieldSet4 = new FieldSet();
	        fieldSet4.setTitle("Detalles adicionales de hospedaje");
	        fieldSet4.setCollapsible(true);
	        fieldSet4.add(txtcheckIn);
	        fieldSet4.add(txtcheckOut);
	        fieldSet4.add(txtToalla);
	        fieldSet4.add(txtTotal);
	        fieldSet4.add(txtPago);
	        fieldSet4.add(txtVoucher);
	        fieldSet4.add(txtDebe);
	        fieldSet4.add(txtReservationDate);
	        fieldSet4.add(txtNumberOfNights);
	        

	        
	        /*fieldSet.add(fieldSet1);
	        fieldSet.add(fieldSet2);
	        fieldSet.add(fieldSet3);
	        fieldSet.add(fieldSet4);*/
	        fieldSet.setClosable(true);
	        
	        fieldSet1.setVisible(true);
	        fieldSet2.setVisible(true);
	        fieldSet3.setVisible(true);
	        fieldSet4.setVisible(true);
	        
	        HorizontalPanel panel = new HorizontalPanel();
	        panel.add(fieldSet1);
	        panel.add(fieldSet2);
	        panel.add(fieldSet3);
	        panel.add(fieldSet4);
	        
	        fieldSet.add(panel);

	        return fieldSet;
	}

}
